﻿using CarAppDomain.CarParts.IService;
using CarAppDomain.CarType.IService;
using CarAppDto.CarParts.CarPartsDtos;
using D.UtilCore;
using D.UtilCore.Dtos;
using D.UtilCore.Filters;
using D.UtilSqlsugarOrm;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace CarAppAPI.CarType
{
    /// <summary>
    /// 区域模块
    /// </summary>
    [Route("/api/[controller]/[action]")]
    [Authorize]
    public class CarPartsController : BaseApiController
    {

        private readonly ICarPartsService _service;
        public CarPartsController(ICarPartsService service)
        {
            _service = service;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="reqModel"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> Add([FromBody] ReqAddCarParts reqModel)
        {
            reqModel.CreateUser = Account;
            return await _service.AddCarPartsAsync(reqModel);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{ids}"), TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> Delete(string ids)
        {
            var idsArray = ids.Split(",");
            return await _service.DeleteCarPartsAsync(idsArray.ToList());
        }

        /// <summary>
        /// 修改
        /// </summary> 
        /// <param name="reqModel"></param>
        /// <returns></returns>
        [HttpPut, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> Update([FromBody] ReqUpdateCarParts reqModel)
        {
            reqModel.UpdateUser = Account;
            return await _service.UpdateCarPartsAsync(reqModel);
        }

        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}"), TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<RepCarParts>> Get(string? id)
        {
            return await _service.GetCarPartsAsync(id);
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="reqModel"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<List<RepCarParts>>> List([FromBody] ReqQueryCarPartsList reqModel)
        {
            return await _service.QueryCarPartsListAsync(reqModel);
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<PageModel<RepCarParts>>> Pages([FromBody] ReqQueryCarPartsPage reqQueryPage)
        {
            return await _service.QueryCarPartsPagesAsync(reqQueryPage);
        }
    }
}
